package testCasalib
{
	import flash.events.MouseEvent;
	import org.casalib.display.CasaMovieClip;
    import org.casalib.display.CasaSprite;
    import org.casalib.layout.Distribution;
    import org.casalib.util.DisplayObjectUtil;
	import org.casalib.util.SingletonUtil;

	/**
	 * ...
	 * @author ...
	 */
	public class Casalib_Test extends CasaMovieClip 
	{
		public var dist:Distribution;
		private var _count:uint = 0;

		public function Casalib_Test() 
		{
			super();
			
			stage.addEventListener(MouseEvent.CLICK, _onMouseClick, false, 0, true);
		}
		
		private function _createDistribution():void 
		{
            this.dist = new Distribution(110);
            this.dist.setMargin(0, 5, 5, 0);
			//this.dist.vertical = true;

            this.addChild(this.dist);

            var l:uint = 20;
            var s:CasaSprite;

            while (l--) {
                s = new CasaSprite();
				//s = SingletonUtil.singleton(CasaSprite);
                s.graphics.beginFill(0xFFFFFF);
                s.graphics.drawRect(0, 0, 10, 10);
                s.graphics.endFill();
                this.dist.addChild(s);
            }
            this.dist.position();
			trace(this, this.dist.size, this.dist.width, this.dist.children.length);
		}
		
		private function _destroyDistribution():void 
		{
			this.dist.removeChildrenAndDestroy(true, true);
			this.dist.destroy();
		}
		
		private function _onMouseClick(e:MouseEvent):void 
		{
			switch (_count)
			{
				case 0:
					_count++;
					_createDistribution();
					break;
				
				case 1:
					_count--;
					_destroyDistribution(); 
					break;
				
				case 2:
					_count++;
					break;
				
				case 0:
					_count++;
					break;
			}
		}
		
	}

}